home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power Programmierung
/
Power-Programmierung CD 2 (Tewi)(1994).iso
/
doc
/
mir
/
colrm.c
< prev
next >
Wrap
Text File
|
1992-07-02
|
5KB
|
160 lines
/*
* Usage - colrm from_col to_col < printable_ascii > revised_ascii
*
* COLRM Removes the specified range of columns from each line of an
* ASCII file. This is a clone of the Unix "colrm" utility.
*
* input: A printable ASCII file with less than 512 characters per
* line. Columns number from 1 upward.
*
* output: The same number of lines, but with one segment of columns
* removed from each line.
*
* writeup: MIR TUTORIAL ONE, topic 7
*
* Written: Douglas Lowry Jun 21 90
* Modified: Douglas Lowry Feb 15 92
* Copyright (C) 1992 Marpex Inc.
*
* The MIR (Mass Indexing and Retrieval) Tutorials explain detailed
* usage and co-ordination of the MIR family of programs to analyze,
* prepare and index databases (small through gigabyte size), and
* how to build integrated retrieval software around the MIR search
* engine. The fifth of the five MIR tutorial series explains how
* to extend indexing capability into leading edge search-related
* technologies. For more information, GO IBMPRO on CompuServe;
* MIR files are in the DBMS library. The same files are on the
* Canada Remote Systems BBS. A diskette copy of the Introduction
* is available by mail ($10 US... check, Visa or Mastercard);
* diskettes with Introduction, Tutorial ONE software and the
* shareware Tutorial ONE text cost $29. Shareware registration
* for a tutorial is also $29.
*
* E-mail...
* Compuserve 71431,1337
* Internet doug.lowry%canrem.com
* UUCP canrem!doug.lowry
* Others: doug.lowry@canrem.uucp
*
* FAX... 416 963-5677
*
* "Snail mail"... Douglas Lowry, Ph.D.
* Marpex Inc.
* 5334 Yonge Street, #1102
* North York, Ontario
* Canada M2N 6M2
*
* Related database consultation and preparation services are
* available through:
* Innotech Inc., 2001 Sheppard Avenue E., Suite #118,
* North York, Ontario Canada M2J 4Z7
* Tel. 416 492-3838 FAX 416 492-3843
*
* This program is free software; you may redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* (file 05LICENS) along with this program; if not, write to the
* Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
* USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include <dos.h>
#include <ctype.h>
#include <direct.h>
#define MAX_BYTES 512
#define repeat for(;;)
typedef enum _bool
{ FALSE = 0, TRUE = 1 } Bool;
/*
* declarations
*/
void Usage_(), process();
char *Cmdname_() { return( "colrm" ); }
/*
* MAIN
*/
main( argc, argv )
int argc;
char **argv;
{
int to, from ;
if( argc != 3 || !isdigit( argv[1][0] ))
Usage_();
from = atoi( argv[1] );
to = atoi( argv[2] );
if( to < from )
to = from ;
process( from, to );
exit( 0 );
}
/*
* Usage
*/
void
Usage_()
{
fprintf( stderr,
"\nusage: %s from_col to_col < printable_ascii > revised_ascii\n\n\
Removes the specified range of columns from each line of an\n\
ASCII file. This is a clone of the Unix \"colrm\" utility.\n\n",
Cmdname_() ) ;
fprintf( stderr,
"input: A printable ASCII file with less than 512 characters per\n\
line. Columns number from 1 upward.\n\n\
output: The same number of lines, but with one segment of columns\n\
removed from each line.\n\n\
writeup: MIR TUTORIAL ONE, topic 7\n\n" );
exit( 1 ) ;
}
/*
* PROCESS
*/
void
process( from_col, to_col )
int from_col, to_col ;
{
char line_in[ MAX_BYTES ] ;
int len, i ;
Bool after_nl; /* after a new line */
after_nl = TRUE;
while( gets( line_in ) != NULL )
{
len = strlen( line_in );
if( len > MAX_BYTES - 2 )
{
fprintf( stderr, "FATAL... Line exceeds %d bytes.\n\n",
len );
exit( 1 );
}
for( i = 0 ; ( i < from_col - 1 && i < len ) ; i++ )
putchar( line_in[i] );
for( i = to_col ; i < len ; i++ )
putchar( line_in[i] );
putchar( '\n' );
}
return ;
}